/*
2019-05-14
手动实现instanceof
*/

// A,对象，B,构造函数
function instanceof_custom(A, B){
  if(A.toString()==='[object Object]'){
    let flag=false
    let tmp_proto=A.__proto__;
    while(tmp_proto){
      if(B&&B.prototype===tmp_proto){
        flag=true;
        break;
      }
      tmp_proto=tmp_proto.__proto__;
    }
    return flag;
  }
  throw new TypeError('A类型错误');
}

let ret=instanceof_custom({}, Object);
console.log(ret);

function Foo(){}
var f=new Foo();
console.log(instanceof_custom(f, null));